package com.example.po;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.example.constant.MQConstant;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

/*
 * @className: SysMQMessage
 * @author: chentao
 * @date: 2025/2/28 下午4:54
 * @Version: 1.0
 * @description:
 */
@Data
@TableName(value = "sys_mq_message")
public class SysMQMessage extends Model<SysMQMessage> {

    //消息的id
    @TableId(type = IdType.AUTO)
    private String id;

    //消息的类型
    @TableField(value = "type")
    private String type;

    //队列名称
    @TableField(value = "name")
    private String name;

    //消息的内容
    @TableField(value = "content")
    private String content;

    //消息消费的状态
    @TableField(value = "status")
    private int status = MQConstant.INIT;

    //处理节点
    @TableField(value = "server_key")
    private Long serverKey;

    //重试次数
    @TableField(value = "retry_count")
    private int retryCount;

    //下次重试时间
    @TableField(value = "retry_time")
    private Date retryTime;

    //错误信息
    @TableField(value = "error_message")
    private String errorMessage;

    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time")
    private Date createTime;

    //更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time")
    private Date updateTime;

    public void recalculateFields() {
        if (this.createTime == null) {
            this.createTime = new Date();
        }
        this.updateTime = new Date();
    }
}
